
export default {
  data() {
    return {
    }
  },
  watch: {
    columns: {
      handler(newValue, oldValue) {
        this.dealDialogColumnData()
      },
      deep: true
    }
  },
  mounted() {
    this.dealDialogColumnData()
  },
  activated() {
    // 处理表格错位问题
    if (this.$refs.table && this.$refs.table.doLayout) {
      this.$refs.table.doLayout()
    } else if (this.tableRef && this.tableRef.doLayout) {
      this.tableRef.doLayout()
    }
  },
  methods: {
    async dealDialogColumnData() {
      if (this.$refs.table) {
        await this.dealData(this.$refs.table)
      } else if (this.tableRef) { // 组件mixins
        await this.dealData(this.tableRef)
      }
    },
    async dealData(tableRef) {
      if (typeof tableRef === 'object' && Object.keys(tableRef).length === 0) return
      this.$emit('input', false)
      tableRef.$children.forEach((res) => {
        if (res.columnConfig) {
          const col = this.columns.find((item) => item.prop === res.prop)
          if (!col) return
          res.columnConfig.fixed = col.fixed
          res.columnConfig.sortable = col.sortable
        }
      })
      this.$emit('input', true)
      await this.$nextTick()
      tableRef.doLayout()
      this.$forceUpdate()
    }

  }
}
